import tkinter as tk
import pymysql


# 商品表的删除
def delete_sp():
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    sql = "delete from 商品表 where 商品编号='%s'"
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    connect.close()


# 删除商品界面
def Goods_delete_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="删除商品", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20)
    g10 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    # 生成按钮
    button = tk.Button(window_function, text="删除", command=delete_sp, anchor='s').place(relx=0.2, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.4, rely=0.5)
    # 显示窗口
    window_function.mainloop()


# 员工表的删除
def delete_yg():
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    sql = "delete from 员工表 where 员工编号='%s'"
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    connect.close()


# 删除员工界面
def Goods_delete_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="删除员工", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入员工编号：").grid(row=1, column=0, padx=20)
    g10 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    # 生成按钮
    button = tk.Button(window_function, text="删除", command=delete_yg, anchor='s').place(relx=0.2, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.4, rely=0.5)
    # 显示窗口
    window_function.mainloop()


# 供应商表的删除
def delete_gys():
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    sql = "delete from 供应商表 where 供应商编号='%s'"
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    connect.close()


# 删除供应商界面
def Goods_delete_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="删除供应商", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入供应商编号：").grid(row=1, column=0, padx=20)
    g10 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    # 生成按钮
    button = tk.Button(window_function, text="删除", command=delete_gys, anchor='s').place(relx=0.2, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.4, rely=0.5)
    # 显示窗口
    window_function.mainloop()


# 采购主表的删除
def delete_cg():
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    sql = "delete from 采购主表 where 采购清单号='%s'"
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    connect.close()


# 删除采购内容界面
def Goods_delete_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="删除采购内容", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入采购清单号：").grid(row=1, column=0, padx=20)
    g10 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    # 生成按钮
    button = tk.Button(window_function, text="删除", command=delete_cg, anchor='s').place(relx=0.2, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.4, rely=0.5)
    # 显示窗口
    window_function.mainloop()


# 采购明细表的删除
def delete_mx():
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    sql = "delete from 采购明细表 where 采购明细号='%s'"
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    connect.close()


# 删除采购明细界面
def Goods_delete_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="删除采购明细", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入采购明细号：").grid(row=1, column=0, padx=20)
    g10 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    # 生成按钮
    button = tk.Button(window_function, text="删除采购明细", command=delete_mx, anchor='s').place(relx=0.2, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.4, rely=0.5)
    # 显示窗口
    window_function.mainloop()


def to_mainpage():
    window.destroy()
    mainpage()


# 主界面
def mainpage():
    global window
    window = tk.Tk()
    window.title("超市管理系统")
